<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>作业提交详情</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<body>
<br>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">学生搜索</label>
            <div class="layui-input-inline">
                <input type="text" name="key" placeholder="学生学号/姓名" class="layui-input">
                <input name="taskId" type="hidden" id="taskId">
                <input name="taskName" type="hidden" id="taskName">
                <input name="courseName" type="hidden" id="courseName">
                <input name="classes" type="hidden" id="classes">
            </div>
        </div>
        <div class="layui-form-item layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user-query">
                <i class="layui-icon layui-icon-search"></i>
                查询
            </button>
        </div>
    </div>
</form>
<table id="user-table" lay-filter="user-table" lay-size="lg"></table>
</body>
<script type="text/html" id="log-bar">
    <button title="" class="layui-btn layui-btn layui-btn-xs" lay-event="check">
        <i class="layui-icon layui-icon-right"></i>
    </button>
</script>
<script type="text/html" id="log-toolbar">
    <button class="layui-btn layui-btn-sm" lay-event="allDownload">
        <i class="layui-icon layui-icon-download-circle"></i>
        一键下载班级文件
    </button>
</script>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'laydate', 'loading'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;


        form.on('submit(user-query)', function (data) {

            table.reload('user-table', {
                url: '/Task/searchOfTaskSubmit',
                method: 'post',
                page: {
                    layout: ['count', 'prev', 'page', 'next', 'skip']
                    , curr: 1
                    , groups: 3
                    , last: false
                }
                , where: {
                    key: data.field.key,
                    taskId: data.field.taskId
                }
            })
            return false;
        });


        table.on('toolbar(user-table)', function (obj) {
            if (obj.event === 'allDownload') {
                window.allDownload(obj);
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'search') {
                //obj.del();
                window.search(obj);
            }
        });
        table.on('tool(user-table)', function (obj) {
            if (obj.event === 'check') {
                window.check(obj);
            } else if (obj.event === 'refresh') {
                window.refresh(obj);
            }
        });
        window.check = function (obj) {
            let checkText;
            if (obj.data['checkStatus'] === 'false') {
                checkText = '未批改'
            } else {
                checkText = '已批改'
            }
            layer.open({
                type: 2,
                title: obj.data['realName'] + '（' + obj.data['userId'] + '）' + obj.data['taskName'] + '完成情况' + "（" + checkText + "）",
                shade: 0.1,
                shadeClose: true,
                area: ['100%', '100%'],
                content: 'TeaCheckHomework.html',
                success: function (layero, index) {
                    let body = layer.getChildFrame('body', index);
                    //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    let iframeWin = window[layero.find('iframe')[0]['name']]
                    body.find('#courseName').append(obj.data['courseName'])
                    body.find('#classes').append(obj.data['classes'])
                    body.find('#taskName').append(obj.data['taskName'])
                    body.find('#userId').val(obj.data['userId'])
                    body.find('#taskId').val(obj.data['taskId'])
                    body.find('#homeworkContent').append(obj.data['uploadClaim'])
                    body.find('#homeworkFiles').append('<a target="_blank" href="' +
                        obj.data['uploadFilePath'] +
                        '">' + obj.data['fileName'] + '</a>')
                }
            });
        };


        window.allDownload = function (obj) {
            console.log(obj);
            layer.open({
                title: '批量下载提示',
                content: '<i class="layui-icon layui-icon-download-circle" style="font-size: 35px">' +
                    '&nbsp;' +
                    '</i>是否开始下载该班级文件（将自动打包）'
                , btn: ['确认', '取消']
                , yes: function (index, layero) {
                    layer.msg('开始批量下载文件');
                    let fileForm = $("<form action='/Task/teacherDownloadStudentTask' method='post'>" +
                        "</form>")
                    fileForm.append("<input type='hidden' name='taskId' value='" + $('#taskId').val() + "'/>")
                    fileForm.append("<input type='hidden' name='taskName' value='" + $('#taskName').val() + "'/>")
                    fileForm.append("<input type='hidden' name='classes' value='" + $('#classes').val() + "'/>")
                    fileForm.append("<input type='hidden' name='courseName' value='" + $('#courseName').val() + "'/>")
                    $(document.body).append(fileForm);
                    fileForm.submit();
                    fileForm.remove();
                }
                , btn2: function (index, layero) {
                    //return false 开启该代码可禁止点击该按钮关闭
                }
                , cancel: function () {
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
        }

        window.refresh = function (param) {
            table.reload('user-table', {
                url: "/Task/getStudentsTaskByTaskId",
                method: "post",
                where: {
                    taskId: $('taskId').val()
                },
            });
        }
    })
</script>
</html>